package com.keller.test.main.presenter;

import com.keller.test.main.model.IWetherImpl;
import com.keller.test.main.model.IWetherModel;
import com.keller.test.main.view.IWetherView;

/**
 * 用途：
 * 作者： wangkangle
 * Email: wkl_2052@qq.com
 * weixin: feimeng16
 * 版本：1.0
 * 创建日期：Administrator on 2017-11-23 10:47
 */

public class WetherPresenter {

    IWetherModel mModel;
    IWetherView mView;

    public WetherPresenter(IWetherView view) {
        this.mView = view;
        mModel = new IWetherImpl();
    }



    private void showDialog(){
        if (mView != null){
            mView.showWaitingDialog();
        }
    }

    private void saveInfo(String s){
        mModel.setInfo(s);
    }




    public void requestWetherInfo(){
            new Thread(new Runnable() {
                @Override
                public void run() {

                    try {
                        showDialog();
                        //打开等待对话框
                        showDialog();
                        //模拟网络耗时
                        Thread.sleep(6000);

                        String info = "21度，晴转多云";
                        saveInfo(info);

                        mView.onInfoUpdate(info);


                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }finally {
                        mView.dissmissWaitingDialog();
                    }



                }
            }).start();


    }
}
